package ar.com.android.restoapp.forms;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import ar.com.android.restoapp.forms.R;
import ar.com.android.restoapp.entities.Tables;
import ar.com.android.restoapp.providers.TablesProvider;

public class CommentsPopUpActivity extends Activity {

	EditText etComments;
	Button butSave;
	Integer selectedTable;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_comments_pop_up);
		
		Bundle bundle = getIntent().getExtras();
		
		selectedTable =  bundle.getInt("selectedTable");
		
		etComments = (EditText) findViewById(R.id.etComments);
		butSave = (Button) findViewById(R.id.butSave);
		
		TablesProvider tablesProvider = new TablesProvider(CommentsPopUpActivity.this);
		Tables table = tablesProvider.getTable(selectedTable);
		
		etComments.setText(table.getComments());
	}
	
	public void onClickSave(View v) throws Exception
    {
		TablesProvider tablesProvider = new TablesProvider(CommentsPopUpActivity.this);
		Tables table = tablesProvider.getTable(selectedTable);
		
		table.setComments(etComments.getText().toString());
		
		tablesProvider.updateTable(table);
		
		this.finish();
    }
}
